Skip to content

feat: add initial username INBOUND and Usync support#2480

Merged
purpshell merged 4 commits intoWhiskeySockets:masterfrom
gusquadri:username-ingest
Apr 24, 2026
Merged

feat: add initial username INBOUND and Usync support#2480
purpshell merged 4 commits intoWhiskeySockets:masterfrom
gusquadri:username-ingest

Conversation

@gusquadri
Copy link
Copy Markdown
Contributor

@gusquadri gusquadri commented Apr 12, 2026

This PR adds inbound username support in Baileys for when WhatsApp starts sending those fields.

Based on the current WA Web implementation, username maps to the user’s LID, not to a separate independent third identifier.

Summary by CodeRabbit

  • New Features
    • Added username support for contacts, capturing and displaying usernames across the system
    • Group metadata now includes owner and subject owner username information
    • Messages and participant data enriched with username fields for improved identification

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6965eec7-bb97-48ff-857f-d5f34ad25cf1

📥 Commits

Reviewing files that changed from the base of the PR and between 8e5093c and 94f2a77.

📒 Files selected for processing (16)
  • src/Socket/groups.ts
  • src/Socket/messages-recv.ts
  • src/Types/Contact.ts
  • src/Types/Events.ts
  • src/Types/GroupMetadata.ts
  • src/Types/Message.ts
  • src/Utils/chat-utils.ts
  • src/Utils/decode-wa-message.ts
  • src/Utils/history.ts
  • src/Utils/process-message.ts
  • src/Utils/sync-action-utils.ts
  • src/WAUSync/Protocols/USyncContactProtocol.ts
  • src/WAUSync/Protocols/USyncUsernameProtocol.ts
  • src/WAUSync/Protocols/index.ts
  • src/WAUSync/USyncQuery.ts
  • src/WAUSync/USyncUser.ts

📝 Walkthrough

Walkthrough

This PR introduces username support across the Baileys codebase by adding optional username and related fields to contacts, messages, group metadata, and events, while implementing a new USyncUsernameProtocol for parsing username binary elements in the USync system.

Changes

Cohort / File(s) Summary
Type Definitions
src/Types/Contact.ts, src/Types/GroupMetadata.ts, src/Types/Message.ts, src/Types/Events.ts
Extended four type definitions with optional username-related fields: Contact adds username, GroupMetadata adds ownerUsername/subjectOwnerUsername/descOwnerUsername/authorUsername, WAMessageKey adds remoteJidUsername/participantUsername, and BaileysEventMap group events add authorUsername.
Message Handling
src/Socket/groups.ts, src/Socket/messages-recv.ts
Enhanced group metadata extraction to capture username fields (participant_username, s_o_username, creator_username) and enriched incoming message handling to include participant usernames in group change payloads and message keys.
Message Processing Utilities
src/Utils/decode-wa-message.ts, src/Utils/process-message.ts
Updated message decoding to extract remoteJidUsername and participantUsername from message attributes, and enriched group event emissions to include authorUsername derived from message keys.
Contact Processing
src/Utils/chat-utils.ts, src/Utils/sync-action-utils.ts, src/Utils/history.ts
Extended contact object construction across sync actions and conversation history to include the username field when available.
USync Protocols
src/WAUSync/Protocols/USyncUsernameProtocol.ts, src/WAUSync/Protocols/USyncContactProtocol.ts, src/WAUSync/Protocols/index.ts, src/WAUSync/USyncUser.ts, src/WAUSync/USyncQuery.ts
Implemented new USyncUsernameProtocol for parsing username nodes, modified USyncContactProtocol to support username-based contact nodes, extended USyncUser with username properties and builder methods, and added withUsernameProtocol() chainable method to USyncQuery.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit hops through fields of names, 🐰
Where usernames now light the way,
From contacts dancing in the frames,
To messages that brightly play—
Identity flows fresh and bright! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@whiskeysockets-bot
Copy link
Copy Markdown
Contributor

whiskeysockets-bot commented Apr 12, 2026

Thanks for opening this pull request and contributing to the project!

The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch.

In the meantime, anyone in the community is encouraged to test this pull request and provide feedback.

✅ How to confirm it works

If you’ve tested this PR, please comment below with:

Tested and working ✅

This helps us speed up the review and merge process.

📦 To test this PR locally:

# NPM
npm install @whiskeysockets/baileys@gusquadri/Baileys#username-ingest

# Yarn (v2+)
yarn add @whiskeysockets/baileys@gusquadri/Baileys#username-ingest

# PNPM
pnpm add @whiskeysockets/baileys@gusquadri/Baileys#username-ingest

If you encounter any issues or have feedback, feel free to comment as well.

@Santosl2
Copy link
Copy Markdown
Contributor

Nice!

@purpshell purpshell marked this pull request as ready for review April 24, 2026 15:20
@purpshell purpshell enabled auto-merge (squash) April 24, 2026 15:20
@purpshell purpshell disabled auto-merge April 24, 2026 15:20
@purpshell purpshell merged commit 25a4ef7 into WhiskeySockets:master Apr 24, 2026
4 of 5 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Baileys Review Cycle Apr 24, 2026
rsalcara added a commit to rsalcara/InfiniteAPI that referenced this pull request Apr 25, 2026
* feat: add inbound username support and USync username protocol

Aligns with Baileys upstream PR WhiskeySockets#2480. WhatsApp is rolling out an
inbound username field that maps to the user's LID. This change is
purely additive — it captures and propagates the new optional field
through types, decoders, USync queries, and group/contact events.

Skipped intentionally to preserve InfiniteAPI's LID/PN customization:
- handleGroupNotification in messages-recv.ts (custom LID->PN flow on
  groups.upsert / participants.map). Username for these specific
  events still flows via process-message's emitParticipantsUpdate
  (reads message.key.participantUsername added in decode-wa-message).

Carousel/buttons code (messages.ts, messages-send.ts) untouched.

Co-Authored-By: Renato Alcara
ViperTecCorporation added a commit to ViperTecCorporation/Baileys that referenced this pull request Apr 26, 2026
eduair94 added a commit to eduair94/Baileys that referenced this pull request Apr 27, 2026
…#2480), abprops fix (WhiskeySockets#2473), JID streamlining (WhiskeySockets#2352), app state sync resilience (WhiskeySockets#2350), history sync perf (WhiskeySockets#2333), tctoken lifecycle (WhiskeySockets#2339), albums (WhiskeySockets#2058), enriched call events (WhiskeySockets#2355), updateBlockStatus validation (WhiskeySockets#2265), music-metadata pin (WhiskeySockets#2413), dup-imports fix (WhiskeySockets#2496)

Resolved chats.ts import conflicts: union of fork + upstream symbols (added ensureLTHashStateVersion, isAppStateSyncIrrecoverable, isMissingKeyError, MAX_SYNC_ATTEMPTS, isLidUser, isPnUser, isHostedLidUser, isHostedPnUser). yarn.lock taken from upstream.
eduair94 added a commit to eduair94/Baileys that referenced this pull request Apr 27, 2026
… state resilience WhiskeySockets#2350, JID streamlining WhiskeySockets#2352, abprops fix WhiskeySockets#2473) + cherry-picks (decodeFrame crash-loop guard WhiskeySockets#2402, LID-aware onWhatsApp WhiskeySockets#2403)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants